home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SNNSV32.ZIP / SNNSv3.2 / kernel / sources / kr_art2.c < prev    next >
C/C++ Source or Header  |  1994-04-25  |  57KB  |  2,246 lines

  1. /*****************************************************************************
  2.   FILE           : kr_art2.c
  3.   SHORTNAME      : kr_art2
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : SNNS Kernel Functions for ART2 networks
  7.   NOTES          :
  8.  
  9.   AUTHOR         : Kai-Uwe Herrmann
  10.   DATE           : 17.05.92
  11.  
  12.   CHANGED BY     : Sven Doering
  13.   IDENTIFICATION : @(#)kr_art2.c    1.9 3/15/94
  14.   SCCS VERSION   : 1.9
  15.   LAST CHANGE    : 3/15/94
  16.  
  17.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  18.  
  19. ******************************************************************************/
  20.  
  21. /*#################################################
  22.  
  23. GROUP: include files
  24.  
  25. #################################################*/
  26.  
  27.  
  28.  
  29.  
  30. #include <stdlib.h>
  31.  
  32. #ifndef NULL /* if NULL pointer is not defined include stdio.h */
  33. #include <stdio.h>
  34. #endif
  35.  
  36. #include <math.h>
  37.  
  38.  
  39. #include "kr_const.h"
  40. #include "kr_mac.h"
  41. #include "kr_def.h"
  42. #include "kr_typ.h"
  43. #include "kr_funcs.h"
  44. #include "kernel.h"
  45. #include "glob_typ.h"
  46. #include "kr_art.h"     /*  Function prototypes for ART networks */
  47. #include "krart_df.h"   /*  Definitions for ART networks */
  48. #include "kr_art2.ph"
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55. /*#################################################
  56.  
  57. GROUP: declaration of module functions
  58.  
  59. #################################################*/
  60.  
  61.  
  62.  
  63.  
  64. /*#################################################
  65.  
  66. GROUP: IMPLEMENTATION SECTION of
  67.        ART 2 kernel functions visible to other
  68.        modules
  69.        by Kai-Uwe Herrmann
  70.  
  71. #################################################*/
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  79. krui_err kra2_sort (void)
  80. {
  81.  
  82.    TopoPtrArray        topo_ptr = topo_ptr_array;
  83.    int                 ret_code = KRERR_NO_ERROR;
  84.  
  85.    int                 no_of_w_units = 0;
  86.    int                 no_of_x_units = 0;
  87.    int                 no_of_u_units = 0;
  88.    int                 no_of_v_units = 0;
  89.    int                 no_of_p_units = 0;
  90.    int                 no_of_q_units = 0;
  91.    int                 no_of_r_units = 0;
  92.    int                 no_of_rst_units = 0;
  93.  
  94.    /* initialize ART2 sorting
  95.    */
  96.    krart_init_sorting ();
  97.  
  98.  
  99.    /* get no of input units and no of recognition units
  100.    */
  101.    NoOfInputUnits         = krart_get_NoOfInputUnits ();
  102.    Art2_NoOfRecUnits      = kra2_get_NoOfRecUnits ();
  103.  
  104.    if (NoOfInputUnits == 0) {
  105.       ret_code = KRERR_NO_INPUT_UNITS;
  106.       return (ret_code);
  107.    } /*if*/
  108.  
  109.    if (Art2_NoOfRecUnits == 0) {
  110.       TOPO_MSG_NO_OF_UNITS_IN_LAYER ("recognition");
  111.    } /*if*/
  112.  
  113.  
  114.    /* insert a NULL pointer to topo ptr array for left limitation
  115.    */
  116.    *topo_ptr++ = NULL;
  117.  
  118.  
  119.    /* determine unit types and insert them into topo ptr array
  120.    */
  121.  
  122.    topo_layer[0] = topo_ptr;
  123.  
  124.  
  125.    /* determine input units
  126.    */
  127.    topo_layer[0] = topo_ptr;
  128.    ret_code = kra2_get_InpUnits (&topo_ptr);
  129.  
  130.    if (ret_code != KRERR_NO_ERROR) {
  131.       return (ret_code);
  132.    } /*if*/
  133.  
  134.    *topo_ptr++ = NULL;
  135.  
  136.    /* determine w units
  137.    */
  138.    topo_layer[1] = topo_ptr;
  139.    ret_code = kra2_get_WUnits (&topo_ptr, &no_of_w_units);
  140.  
  141.    if (ret_code != KRERR_NO_ERROR) {
  142.       return (ret_code);
  143.    } /*if*/
  144.  
  145.    if (no_of_w_units != NoOfInputUnits) {
  146.       TOPO_MSG_NO_OF_UNITS_IN_LAYER ("w");
  147.    } /*if*/
  148.  
  149.    *topo_ptr++ = NULL;
  150.  
  151.  
  152.    /* determine x units
  153.    */
  154.    topo_layer[2] = topo_ptr;
  155.    ret_code = kra2_get_XUnits (&topo_ptr, &no_of_x_units);
  156.  
  157.    if (ret_code != KRERR_NO_ERROR) {
  158.       return (ret_code);
  159.    } /*if*/
  160.  
  161.    if (no_of_x_units != NoOfInputUnits) {
  162.       TOPO_MSG_NO_OF_UNITS_IN_LAYER ("x");
  163.    } /*if*/
  164.  
  165.    *topo_ptr++ = NULL;
  166.  
  167.  
  168.    /* determine u units
  169.    */
  170.    topo_layer[3] = topo_ptr;
  171.    ret_code = kra2_get_UUnits (&topo_ptr, &no_of_u_units);
  172.  
  173.    if (ret_code != KRERR_NO_ERROR) {
  174.       return (ret_code);
  175.    } /*if*/
  176.  
  177.    if (no_of_u_units != NoOfInputUnits) {
  178.       TOPO_MSG_NO_OF_UNITS_IN_LAYER ("u");
  179.    } /*if*/
  180.  
  181.    *topo_ptr++ = NULL;
  182.  
  183.  
  184.    /* determine v units
  185.    */
  186.    topo_layer[4] = topo_ptr;
  187.    ret_code = kra2_get_VUnits (&topo_ptr, &no_of_v_units);
  188.  
  189.    if (ret_code != KRERR_NO_ERROR) {
  190.       return (ret_code);
  191.    } /*if*/
  192.  
  193.    if (no_of_v_units != NoOfInputUnits) {
  194.       TOPO_MSG_NO_OF_UNITS_IN_LAYER ("v");
  195.    } /*if*/
  196.  
  197.    *topo_ptr++ = NULL;
  198.  
  199.  
  200.    /* determine p units
  201.    */
  202.    topo_layer[5] = topo_ptr;
  203.    ret_code = kra2_get_PUnits (&topo_ptr, &no_of_p_units);
  204.  
  205.    if (ret_code != KRERR_NO_ERROR) {
  206.       return (ret_code);
  207.    } /*if*/
  208.  
  209.    if (no_of_p_units != NoOfInputUnits) {
  210.       TOPO_MSG_NO_OF_UNITS_IN_LAYER ("p");
  211.    } /*if*/
  212.  
  213.    *topo_ptr++ = NULL;
  214.  
  215.  
  216.    /* determine q units
  217.    */
  218.    topo_layer[6] = topo_ptr;
  219.    ret_code = kra2_get_QUnits (&topo_ptr, &no_of_q_units);
  220.  
  221.    if (ret_code != KRERR_NO_ERROR) {
  222.       return (ret_code);
  223.    } /*if*/
  224.  
  225.    if (no_of_q_units != NoOfInputUnits) {
  226.       TOPO_MSG_NO_OF_UNITS_IN_LAYER ("q");
  227.    } /*if*/
  228.  
  229.    *topo_ptr++ = NULL;
  230.  
  231.  
  232.    /* determine r units
  233.    */
  234.    topo_layer[7] = topo_ptr;
  235.    ret_code = kra2_get_RUnits (&topo_ptr, &no_of_r_units);
  236.  
  237.    if (ret_code != KRERR_NO_ERROR) {
  238.       return (ret_code);
  239.    } /*if*/
  240.  
  241.    if (no_of_r_units != NoOfInputUnits) {
  242.       TOPO_MSG_NO_OF_UNITS_IN_LAYER ("r");
  243.    } /*if*/
  244.  
  245.    *topo_ptr++ = NULL;
  246.  
  247.  
  248.    /* determine rec units
  249.    */
  250.    topo_layer[8] = topo_ptr;
  251.    ret_code = kra2_get_RecUnits (&topo_ptr);
  252.  
  253.    if (ret_code != KRERR_NO_ERROR) {
  254.       return (ret_code);
  255.    } /*if*/
  256.  
  257.    *topo_ptr++ = NULL;
  258.  
  259.  
  260.    /* determine rst units
  261.    */
  262.    topo_layer[9] = topo_ptr;
  263.    ret_code = kra2_get_RstUnits (&topo_ptr, &no_of_rst_units);
  264.  
  265.    if (ret_code != KRERR_NO_ERROR) {
  266.       return (ret_code);
  267.    } /*if*/
  268.  
  269.    if (no_of_rst_units != Art2_NoOfRecUnits) {
  270.       TOPO_MSG_NO_OF_UNITS_IN_LAYER ("reset");
  271.    } /*if*/
  272.  
  273.    *topo_ptr++ = NULL;
  274.  
  275.  
  276.    /* check if the logical type of really all units is determined
  277.    */
  278.    if (krart_check_undeterminedUnits ()) {
  279.       ret_code = topo_msg.error_code;
  280.       return (ret_code);
  281.    } /*if*/
  282.  
  283.  
  284.    /* Now check the topo ptr array
  285.    */
  286.    ret_code = kra2_TopoPtrArray ();
  287.  
  288.    if (ret_code != KRERR_NO_ERROR) {
  289.       return (ret_code);
  290.    } /*if*/
  291.  
  292.  
  293.    /* Check link structure
  294.    */
  295.    topo_ptr = topo_ptr_array + 1;
  296.  
  297.    /* Check links of input units
  298.    */
  299.    ret_code = kra2_LinksToInpUnits (&topo_ptr);
  300.  
  301.    if (ret_code != KRERR_NO_ERROR) {
  302.       return (ret_code);
  303.    } /*if*/
  304.  
  305.  
  306.    /* Check links of w units
  307.    */
  308.    ret_code = kra2_LinksToWUnits (&topo_ptr);
  309.  
  310.    if (ret_code != KRERR_NO_ERROR) {
  311.       return (ret_code);
  312.    } /*if*/
  313.  
  314.  
  315.    /* Check links of x units
  316.    */
  317.    ret_code = kra2_LinksToXUnits (&topo_ptr);
  318.  
  319.    if (ret_code != KRERR_NO_ERROR) {
  320.       return (ret_code);
  321.    } /*if*/
  322.  
  323.  
  324.    /* Check links of u units
  325.    */
  326.    ret_code = kra2_LinksToUUnits (&topo_ptr);
  327.  
  328.    if (ret_code != KRERR_NO_ERROR) {
  329.       return (ret_code);
  330.    } /*if*/
  331.  
  332.  
  333.    /* Check links of v units
  334.    */
  335.    ret_code = kra2_LinksToVUnits (&topo_ptr);
  336.  
  337.    if (ret_code != KRERR_NO_ERROR) {
  338.       return (ret_code);
  339.    } /*if*/
  340.  
  341.  
  342.    /* Check links of p units
  343.    */
  344.    ret_code = kra2_LinksToPUnits (&topo_ptr);
  345.  
  346.    if (ret_code != KRERR_NO_ERROR) {
  347.       return (ret_code);
  348.    } /*if*/
  349.  
  350.  
  351.    /* Check links of q units
  352.    */
  353.    ret_code = kra2_LinksToQUnits (&topo_ptr);
  354.  
  355.    if (ret_code != KRERR_NO_ERROR) {
  356.       return (ret_code);
  357.    } /*if*/
  358.  
  359.  
  360.    /* Check links of r units
  361.    */
  362.    ret_code = kra2_LinksToRUnits (&topo_ptr);
  363.  
  364.    if (ret_code != KRERR_NO_ERROR) {
  365.       return (ret_code);
  366.    } /*if*/
  367.  
  368.  
  369.    /* Check links of rec units
  370.    */
  371.    ret_code = kra2_LinksToRecUnits (&topo_ptr);
  372.  
  373.    if (ret_code != KRERR_NO_ERROR) {
  374.       return (ret_code);
  375.    } /*if*/
  376.  
  377.  
  378.    /* Check links of rst units
  379.    */
  380.    ret_code = kra2_LinksToRstUnits (&topo_ptr);
  381.  
  382.    if (ret_code != KRERR_NO_ERROR) {
  383.       return (ret_code);
  384.    } /*if*/
  385.  
  386.  
  387. /*--------------------------------------------------------------------*/
  388. #if 0
  389. /* this was the preliminary version of the sorting routine for testing*/
  390.                           *topo_ptr++ = NULL;
  391.                           topo_layer[ART2_INP_LAY-1] = topo_ptr;
  392.  
  393.                           Art2_NoOfRecUnits = 0;
  394.                           FOR_ALL_UNITS (unit_ptr) {
  395.                              if (IS_SPECIAL_UNIT (unit_ptr)) {
  396.                                 Art2_NoOfRecUnits++;
  397.                              } /*if*/
  398.                           } /*FOR_ALL_UNITS*/
  399.  
  400.  
  401.                           unit_ptr = unit_array + 1;
  402.  
  403.                           for (i=1; i<= NoOfInputUnits; i++, unit_ptr++) {
  404.                              *topo_ptr++ = unit_ptr;
  405.                              unit_ptr->lln = ART2_INP_LAY;
  406.                           } /*for*/
  407.  
  408.                           *topo_ptr++ = NULL;
  409.                           topo_layer[ART2_W_LAY-1] = topo_ptr;
  410.  
  411.                           for (i=1; i<=NoOfInputUnits; i++, unit_ptr++) {
  412.                              *topo_ptr++ = unit_ptr;
  413.                              unit_ptr->lln = ART2_W_LAY;
  414.                           } /*for*/
  415.  
  416.                           *topo_ptr++ = NULL;
  417.                           topo_layer[ART2_X_LAY-1] = topo_ptr;
  418.  
  419.                           for (i=1; i<=NoOfInputUnits; i++, unit_ptr++) {
  420.                              *topo_ptr++ = unit_ptr;
  421.                              unit_ptr->lln = ART2_X_LAY;
  422.                           } /*for*/
  423.  
  424.                           *topo_ptr++ = NULL;
  425.                           topo_layer[ART2_U_LAY-1] = topo_ptr;
  426.  
  427.                           for (i=1; i<=NoOfInputUnits; i++, unit_ptr++) {
  428.                              *topo_ptr++ = unit_ptr;
  429.                              unit_ptr->lln = ART2_U_LAY;
  430.                           } /*for*/
  431.  
  432.                           *topo_ptr++ = NULL;
  433.                           topo_layer[ART2_V_LAY-1] = topo_ptr;
  434.  
  435.                           for (i=1; i<=NoOfInputUnits; i++, unit_ptr++) {
  436.                              *topo_ptr++ = unit_ptr;
  437.                              unit_ptr->lln = ART2_V_LAY;
  438.                           } /*for*/
  439.  
  440.                           *topo_ptr++ = NULL;
  441.                           topo_layer[ART2_P_LAY-1] = topo_ptr;
  442.  
  443.                           for (i=1; i<=NoOfInputUnits; i++, unit_ptr++) {
  444.                              *topo_ptr++ = unit_ptr;
  445.                              unit_ptr->lln = ART2_P_LAY;
  446.                           } /*for*/
  447.  
  448.                           *topo_ptr++ = NULL;
  449.                           topo_layer[ART2_Q_LAY-1] = topo_ptr;
  450.  
  451.                           for (i=1; i<=NoOfInputUnits; i++, unit_ptr++) {
  452.                              *topo_ptr++ = unit_ptr;
  453.                              unit_ptr->lln = ART2_Q_LAY;
  454.                           } /*for*/
  455.  
  456.  
  457.                           *topo_ptr++ = NULL;
  458.                           topo_layer[ART2_R_LAY-1] = topo_ptr;
  459.  
  460.                           for (i=1; i<=NoOfInputUnits; i++, unit_ptr++) {
  461.                              *topo_ptr++ = unit_ptr;
  462.                              unit_ptr->lln = ART2_R_LAY;
  463.                           } /*for*/
  464.  
  465.  
  466.                           *topo_ptr++ = NULL;
  467.                           topo_layer[ART2_REC_LAY-1] = topo_ptr;
  468.  
  469.                           for (i=1; i<=Art2_NoOfRecUnits; i++, unit_ptr++) {
  470.                              *topo_ptr++ = unit_ptr;
  471.                              unit_ptr->lln = ART2_REC_LAY;
  472.                           } /*for*/
  473.  
  474.                           *topo_ptr++ = NULL;
  475.                           topo_layer[ART2_RST_LAY-1] = topo_ptr;
  476.  
  477.                           for (i=1; i<=Art2_NoOfRecUnits; i++, unit_ptr++) {
  478.                              *topo_ptr++ = unit_ptr;
  479.                              unit_ptr->lln = ART2_RST_LAY;
  480.                           } /*for*/
  481.  
  482.                           *topo_ptr++ = NULL;
  483.                           *topo_ptr   = NULL;
  484. #endif /*#if 0*/
  485. /*-----------------------------------------------------------------*/
  486.  
  487.    return (ret_code);
  488.  
  489. } /* kra2_sort () */
  490. /*___________________________________________________________________________*/
  491.  
  492.  
  493. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  494. krui_err kra2_init_propagate (void)
  495. {
  496.    int                    ret_code = KRERR_NO_ERROR;
  497.  
  498.    ret_code = kra2_init_i_act ();
  499.  
  500.    if (ret_code != KRERR_NO_ERROR) {
  501.       return (ret_code);
  502.    } /*if*/
  503.  
  504.    ret_code = kra2_init_fix_weights ();
  505.  
  506.    if (ret_code != KRERR_NO_ERROR) {
  507.       return (ret_code);
  508.    } /*if*/
  509.  
  510.    ret_code = krart_reset_activations ();
  511.  
  512.    if (ret_code != KRERR_NO_ERROR) {
  513.       return (ret_code);
  514.    } /*if*/
  515.  
  516.    NoOfDelaySteps = 0;
  517.  
  518.    return (ret_code);
  519.  
  520. } /* kra2_init_propagate () */
  521. /*___________________________________________________________________________*/
  522.  
  523.  
  524.  
  525.  
  526. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  527. krui_err  kra2_set_params (FlintType rho, FlintType a, FlintType b, FlintType c, FlintType d, FlintType theta)
  528. {
  529.    Param_rho   = rho;
  530.    Param_a     = a;
  531.    Param_b     = b;
  532.    Param_c     = c;
  533.    Param_d     = d;
  534.    Param_theta = theta;
  535.    return (KRERR_NO_ERROR);
  536. } /* kra2_set_theta () */
  537. /*___________________________________________________________________________*/
  538.  
  539.  
  540.  
  541.  
  542. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  543. FlintType  kra2_get_rho (void)
  544. {
  545.    return (Param_rho);
  546. } /* kra2_get_Param_rho () */
  547. /*___________________________________________________________________________*/
  548.  
  549.  
  550.  
  551. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  552. FlintType  kra2_get_a (void)
  553. {
  554.    return (Param_a);
  555. } /* kra2_get_Param_a () */
  556. /*___________________________________________________________________________*/
  557.  
  558.  
  559.  
  560. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  561. FlintType  kra2_get_b (void)
  562. {
  563.    return (Param_b);
  564. } /* kra2_get_Param_b () */
  565. /*___________________________________________________________________________*/
  566.  
  567.  
  568.  
  569. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  570. FlintType  kra2_get_c (void)
  571. {
  572.    return (Param_c);
  573. } /* kra2_get_Param_c () */
  574. /*___________________________________________________________________________*/
  575.  
  576.  
  577.  
  578. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  579. FlintType  kra2_get_d (void)
  580. {
  581.    return (Param_d);
  582. } /* kra2_get_Param_d () */
  583. /*___________________________________________________________________________*/
  584.  
  585.  
  586.  
  587. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  588. FlintType  kra2_get_theta (void)
  589. {
  590.    return (Param_theta);
  591. } /* kra2_get_Param_theta () */
  592. /*___________________________________________________________________________*/
  593.  
  594.  
  595.  
  596. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  597. void  kra2_checkReset (void)
  598. {
  599.    FlintType NormR;
  600.  
  601.    NormR = ART2_PARAM_e + kra2_L2_Norm (ART2_R_LAY);
  602.  
  603.    if ((kra2_f1_stable()) && (kra2_topdn_phase()) && (kra2_get_rho() / NormR > 1)) {
  604.       GlobalReset  = TRUE;
  605.    } else {
  606.       GlobalReset  = FALSE;
  607.    } /*if*/
  608.  
  609. } /* kra2_checkReset () */
  610. /*___________________________________________________________________________*/
  611.  
  612.  
  613.  
  614. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  615. bool  kra2_Reset (void)
  616. {
  617.    return (GlobalReset);
  618. } /* kra2_Reset () */
  619. /*___________________________________________________________________________*/
  620.  
  621.  
  622.  
  623.  
  624.  
  625. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  626. void  kra2_init_pattern (void)
  627. {
  628.   TopDownPhase = FALSE;
  629.   f1_stable    = FALSE;
  630.   GlobalReset  = FALSE;
  631. } /* kra2_init_phase () */
  632. /*___________________________________________________________________________*/
  633.  
  634.  
  635.  
  636.  
  637.  
  638. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  639. bool  kra2_topdn_phase (void)
  640. {
  641.   return (TopDownPhase);
  642. } /* kra2_topdn_phase () */
  643. /*___________________________________________________________________________*/
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  652. void   kra2_compute_norms (void)
  653. {
  654.    NormInp = kra2_compute_l2_norm (ART2_INP_LAY);
  655.    NormW   = kra2_compute_l2_norm (ART2_W_LAY);
  656.    NormU   = kra2_compute_l2_norm (ART2_U_LAY);
  657.    NormV   = kra2_compute_l2_norm (ART2_V_LAY);
  658.    NormP   = kra2_compute_l2_norm (ART2_P_LAY);
  659.    NormR   = kra2_compute_l2_norm (ART2_R_LAY);
  660. } /* kra2_compute_norms () */
  661. /*___________________________________________________________________________*/
  662.  
  663.  
  664.  
  665.  
  666.  
  667.  
  668. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  669. FlintType  kra2_L2_Norm (int Layer)
  670. {
  671.    switch (Layer) {
  672.    case ART2_INP_LAY:
  673.       return (NormInp);
  674.    case ART2_W_LAY:
  675.       return (NormW);
  676.    case ART2_U_LAY:
  677.       return (NormU);
  678.    case ART2_V_LAY:
  679.       return (NormV);
  680.    case ART2_P_LAY:
  681.       return (NormP);
  682.    case ART2_R_LAY:
  683.       return (NormR);
  684.    default :
  685.       return (0.0);
  686.    } /* switch */
  687. } /* kra2_L2_Norm () */
  688. /*___________________________________________________________________________*/
  689.  
  690.  
  691.  
  692.  
  693. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  694. bool  kra2_classified (void)
  695. {
  696.  
  697.    /* if the F1-Layer is actually stable, then it is necessary to continue
  698.       propagation for MIN_NO_OF_DELAY_STEPS cycles. Then the information
  699.       has been forwarded from recognition layer to r-units and it may be
  700.       decided about a reset.
  701.  
  702.       if there occurs a reset during the delay propagation steps the no. of
  703.       executed delay propagation steps is reset to 0 and FALSE is returned.
  704.  
  705.       if the F1-Layer becomes unstable during the delay propagation steps, the
  706.       no. of executed delay propagation steps is reset to 0, too and FALSE is
  707.       returned.
  708.    */
  709.  
  710.    if (kra2_topdn_phase() && kra2_f1_stable()) {
  711.       if (NoOfDelaySteps >= MIN_NO_OF_DELAY_STEPS) {
  712.          if ( ! kra2_Reset()) {
  713.             return (TRUE);
  714.          } else {
  715.             NoOfDelaySteps = 0;
  716.             return (FALSE);
  717.          } /*if*/
  718.       } else {
  719.          NoOfDelaySteps++;
  720.          return (FALSE);
  721.       } /*if*/
  722.    } else {
  723.       NoOfDelaySteps = 0;
  724.       return (FALSE);
  725.    } /*if*/
  726.  
  727. } /* kra2_classified () */
  728. /*___________________________________________________________________________*/
  729.  
  730.  
  731.  
  732.  
  733. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  734. bool  kra2_not_classifiable (void)
  735. {
  736.    TopoPtrArray topo_ptr         = topo_layer[ART2_RST_LAY-1];
  737.  
  738.  
  739.    /* if there is one local reset unit that is inactive, then the
  740.       pattern may still be classifiable
  741.    */
  742.    while (*topo_ptr != NULL) {
  743.       if ((*topo_ptr)->Out.output < 0.1) {
  744.          return (FALSE);
  745.       } /*if*/
  746.       topo_ptr++;
  747.    } /*while*/
  748.  
  749.  
  750.    /* all local reset units are active -> pattern not classifiable */
  751.    return (TRUE);
  752.  
  753. } /* kra2_classified () */
  754. /*___________________________________________________________________________*/
  755.  
  756.  
  757.  
  758.  
  759.  
  760. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  761. void  kra2_save_for_stability_check (void)
  762. {
  763.    register TopoPtrArray    topo_ptr ;
  764.  
  765.    topo_ptr = topo_layer[ART2_W_LAY-1];
  766.  
  767.    while (*topo_ptr != NULL) {
  768.       (*topo_ptr)->value_a = (*topo_ptr)->act;
  769.       topo_ptr++;
  770.    } /*while*/
  771.  
  772.    topo_ptr = topo_layer[ART2_X_LAY-1];
  773.  
  774.    while (*topo_ptr != NULL) {
  775.       (*topo_ptr)->value_a = (*topo_ptr)->act;
  776.       topo_ptr++;
  777.    } /*while*/
  778.  
  779.    topo_ptr = topo_layer[ART2_U_LAY-1];
  780.  
  781.    while (*topo_ptr != NULL) {
  782.       (*topo_ptr)->value_a = (*topo_ptr)->act;
  783.       topo_ptr++;
  784.    } /*while*/
  785.  
  786.    topo_ptr = topo_layer[ART2_V_LAY-1];
  787.  
  788.    while (*topo_ptr != NULL) {
  789.       (*topo_ptr)->value_a = (*topo_ptr)->act;
  790.       topo_ptr++;
  791.    } /*while*/
  792.  
  793.    topo_ptr = topo_layer[ART2_P_LAY-1];
  794.  
  795.    while (*topo_ptr != NULL) {
  796.       (*topo_ptr)->value_a = (*topo_ptr)->act;
  797.       topo_ptr++;
  798.    } /*while*/
  799.  
  800.    topo_ptr = topo_layer[ART2_Q_LAY-1];
  801.  
  802.    while (*topo_ptr != NULL) {
  803.       (*topo_ptr)->value_a = (*topo_ptr)->act;
  804.       topo_ptr++;
  805.    } /*while*/
  806.  
  807.    topo_ptr = topo_layer[ART2_R_LAY-1];
  808.  
  809.    while (*topo_ptr != NULL) {
  810.       (*topo_ptr)->value_a = (*topo_ptr)->act;
  811.       topo_ptr++;
  812.    } /*while*/
  813.  
  814. } /* kra2_save_for_stability_check () */
  815. /*___________________________________________________________________________*/
  816.  
  817.  
  818.  
  819.  
  820.  
  821. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  822. void  kra2_check_f1_stability (void)
  823. {
  824.    register TopoPtrArray    topo_ptr;
  825.  
  826.    if (f1_stable && ( ! kra2_topdn_phase())) {
  827.       TopDownPhase = TRUE;
  828.    } /*if*/
  829.  
  830.    if (kra2_Reset() && kra2_topdn_phase()) {
  831.       TopDownPhase = FALSE;
  832.       f1_stable    = FALSE;
  833.    } /*if*/
  834.  
  835.  
  836.    topo_ptr = topo_layer[ART2_W_LAY-1];
  837.  
  838.    while (*topo_ptr != NULL) {
  839.       if ( fabs((*topo_ptr)->value_a-(*topo_ptr)->act) > F1_STABILITY_PARAM ) {
  840.          f1_stable = FALSE;
  841.          return;
  842.       } /*if*/
  843.       topo_ptr++;
  844.    } /*while*/
  845.  
  846.    topo_ptr = topo_layer[ART2_X_LAY-1];
  847.  
  848.    while (*topo_ptr != NULL) {
  849.       if ( fabs((*topo_ptr)->value_a-(*topo_ptr)->act) > F1_STABILITY_PARAM ) {
  850.          f1_stable = FALSE;
  851.          return;
  852.       } /*if*/
  853.       topo_ptr++;
  854.    } /*while*/
  855.  
  856.    topo_ptr = topo_layer[ART2_U_LAY-1];
  857.  
  858.    while (*topo_ptr != NULL) {
  859.       if ( fabs((*topo_ptr)->value_a-(*topo_ptr)->act) > F1_STABILITY_PARAM ) {
  860.          f1_stable = FALSE;
  861.          return;
  862.       } /*if*/
  863.       topo_ptr++;
  864.    } /*while*/
  865.  
  866.    topo_ptr = topo_layer[ART2_V_LAY-1];
  867.  
  868.    while (*topo_ptr != NULL) {
  869.       if ( fabs((*topo_ptr)->value_a-(*topo_ptr)->act) > F1_STABILITY_PARAM ) {
  870.          f1_stable = FALSE;
  871.          return;
  872.       } /*if*/
  873.       topo_ptr++;
  874.    } /*while*/
  875.  
  876.    topo_ptr = topo_layer[ART2_P_LAY-1];
  877.  
  878.    while (*topo_ptr != NULL) {
  879.       if ( fabs((*topo_ptr)->value_a-(*topo_ptr)->act) > F1_STABILITY_PARAM ) {
  880.          f1_stable = FALSE;
  881.          return;
  882.       } /*if*/
  883.       topo_ptr++;
  884.    } /*while*/
  885.  
  886.    topo_ptr = topo_layer[ART2_Q_LAY-1];
  887.  
  888.    while (*topo_ptr != NULL) {
  889.       if ( fabs((*topo_ptr)->value_a-(*topo_ptr)->act) > F1_STABILITY_PARAM ) {
  890.          f1_stable = FALSE;
  891.          return;
  892.       } /*if*/
  893.       topo_ptr++;
  894.    } /*while*/
  895.  
  896.    topo_ptr = topo_layer[ART2_R_LAY-1];
  897.  
  898.    while (*topo_ptr != NULL) {
  899.       if ( fabs((*topo_ptr)->value_a-(*topo_ptr)->act) > F1_STABILITY_PARAM ) {
  900.          f1_stable = FALSE;
  901.          return;
  902.       } /*if*/
  903.       topo_ptr++;
  904.    } /*while*/
  905.  
  906.    f1_stable = TRUE;
  907.  
  908.    return;
  909.  
  910. } /* kra2_check_f1_stability () */
  911. /*___________________________________________________________________________*/
  912.  
  913.  
  914.  
  915.  
  916. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  917. bool  kra2_f1_stable (void)
  918. {
  919.    return (f1_stable);
  920. } /* kra2_f1_stable () */
  921. /*___________________________________________________________________________*/
  922.  
  923.  
  924.  
  925. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  926. int  kra2_getClassNo (void)
  927. {
  928.     TopoPtrArray   topo_ptr = topo_layer[ART2_REC_LAY-1];
  929.     int            i;
  930.  
  931.     /* if ART2 sorting wasn't performed then return negative value
  932.        to indicate mistake
  933.     */
  934.     if (topo_ptr == NULL) {
  935.        return (-1);
  936.     } /*if*/
  937.  
  938.     /* look for winning unit */
  939.     for (i = 1;
  940.          (i <= Art2_NoOfRecUnits) || ((*topo_ptr)->Out.output == kra2_get_d());
  941.          i++, topo_ptr++
  942.         );
  943.  
  944.     if ((i > Art2_NoOfRecUnits) && ((*topo_ptr)->Out.output < kra2_get_d())) {
  945.        return (-1);
  946.     } else {
  947.        return (topo_ptr - topo_layer[ART2_REC_LAY-1] + 1);
  948.     } /*if*/
  949.  
  950. } /* kra2_getClassNo () */
  951. /*___________________________________________________________________________*/
  952.  
  953.  
  954.  
  955.  
  956. /*#################################################
  957.  
  958. GROUP: IMPLEMENTATION SECTION of
  959.        ART 2 kernel functions, local to this module
  960.        by Kai-Uwe Herrmann
  961.  
  962. #################################################*/
  963.  
  964.  
  965.  
  966.  
  967.  
  968. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  969. static void   kra2_set_fix_weight (struct Unit *src_unit, struct Unit *trgt_unit, FlintType *weight)
  970. {
  971.  
  972.    if ((src_unit == NULL) || (trgt_unit == NULL)) {
  973.       return;
  974.    } /*if*/
  975.  
  976.    switch (src_unit->lln) {
  977.  
  978.    case ART2_INP_LAY:
  979.  
  980.       switch (trgt_unit->lln) {
  981.       case ART2_W_LAY:
  982.          *weight = ART2_LINK_INP_W;
  983.          break;
  984.       case ART2_R_LAY:
  985.          *weight = ART2_LINK_INP_R;
  986.          break;
  987.       } /*switch*/
  988.  
  989.       break;
  990.  
  991.    case ART2_W_LAY:
  992.  
  993.       switch (trgt_unit->lln) {
  994.       case ART2_X_LAY:
  995.          *weight = ART2_LINK_W_X;
  996.          break;
  997.       } /*switch*/
  998.       break;
  999.  
  1000.    case ART2_X_LAY:
  1001.  
  1002.       *weight = ART2_LINK_X_V;
  1003.       break;
  1004.  
  1005.    case ART2_U_LAY:
  1006.  
  1007.       switch (trgt_unit->lln) {
  1008.       case ART2_W_LAY:
  1009.          *weight = ART2_LINK_U_W(kra2_get_a());
  1010.          break;
  1011.       case ART2_P_LAY:
  1012.          *weight = ART2_LINK_U_P;
  1013.          break;
  1014.       default :
  1015.          break;
  1016.       } /* switch */
  1017.       break;
  1018.  
  1019.    case ART2_V_LAY:
  1020.  
  1021.       switch (trgt_unit->lln) {
  1022.       case ART2_U_LAY:
  1023.          *weight = ART2_LINK_V_U;
  1024.          break;
  1025.       default :
  1026.          break;
  1027.       } /* switch */
  1028.       break;
  1029.  
  1030.    case ART2_P_LAY:
  1031.  
  1032.       switch (trgt_unit->lln) {
  1033.       case ART2_Q_LAY:
  1034.          *weight = ART2_LINK_P_Q;
  1035.          break;
  1036.       case ART2_R_LAY:
  1037.          *weight = ART2_LINK_P_R(kra2_get_c());
  1038.          break;
  1039.       default :
  1040.          break;
  1041.       } /* switch */
  1042.       break;
  1043.  
  1044.    case ART2_Q_LAY:
  1045.  
  1046.       *weight = ART2_LINK_Q_V(kra2_get_b());
  1047.       break;
  1048.  
  1049.    case ART2_R_LAY:
  1050.  
  1051.       /* doesn't have outgoing links because Norm of R is computed
  1052.          within the function kra2_L2_Norm and not in a unit
  1053.       */
  1054.       break;
  1055.  
  1056.    case ART2_REC_LAY:
  1057.  
  1058.       if (trgt_unit->lln == ART2_RST_LAY) {
  1059.          *weight = ART2_LINK_REC_RST;
  1060.       } /*if*/
  1061.       break;
  1062.  
  1063.    case ART2_RST_LAY:
  1064.  
  1065.       switch (trgt_unit->lln) {
  1066.       case ART2_RST_LAY:
  1067.          *weight = ART2_LINK_RST_RST;
  1068.          break;
  1069.       case ART2_REC_LAY:
  1070.          *weight = ART2_LINK_RST_REC(kra2_get_d());
  1071.          break;
  1072.       default :
  1073.          break;
  1074.       } /* switch */
  1075.       break;
  1076.  
  1077.    } /* switch */
  1078.  
  1079.  
  1080. } /* kra2_set_fix_weights () */
  1081. /*___________________________________________________________________________*/
  1082.  
  1083.  
  1084.  
  1085. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  1086. static FlintType kra2_compute_l2_norm (int Layer)
  1087. {
  1088.    register TopoPtrArray    topo_ptr = topo_layer[Layer-1];
  1089.    register FlintType       sum = 0.0;
  1090.    register FlintType       val;
  1091.  
  1092.    while (*topo_ptr != NULL) {
  1093.       val = (*topo_ptr)->Out.output;
  1094.       sum += val * val;
  1095.       topo_ptr++;
  1096.    } /*while*/
  1097.    return ( sqrt((double) sum) );
  1098. }
  1099. /*___________________________________________________________________________*/
  1100.  
  1101.  
  1102.  
  1103. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  1104. static int kra2_get_NoOfRecUnits (void)
  1105. {
  1106.    register struct Unit  *unit_ptr;
  1107.    int                   count           = 0;
  1108.  
  1109.  
  1110.    FOR_ALL_UNITS (unit_ptr) {
  1111.  
  1112.       if (IS_SPECIAL_UNIT(unit_ptr)) {
  1113.          count++;
  1114.       } /*if*/
  1115.  
  1116.    } /*FOR_ALL_UNITS*/
  1117.  
  1118.    return (count);
  1119.  
  1120.  
  1121. } /* kra2_get_NoOfRecUnits () */
  1122. /*___________________________________________________________________________*/
  1123.  
  1124.  
  1125.  
  1126. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  1127. static krui_err kra2_get_InpUnits (TopoPtrArray *topo_ptr)
  1128. {
  1129.    register struct Unit  *unit_ptr;
  1130.  
  1131.    krui_err              ret_code = KRERR_NO_ERROR;
  1132.  
  1133.  
  1134.    FOR_ALL_UNITS (unit_ptr) {
  1135.  
  1136.       if (IS_INPUT_UNIT (unit_ptr)) {
  1137.  
  1138.          if (!(CHECK_ACT_FUNC(unit_ptr, ART2_ACTF_INP))) {
  1139.             TOPO_MSG_ACT_FUNC (unit_ptr);
  1140.          } /*if*/
  1141.  
  1142.          if (!(CHECK_OUT_FUNC(unit_ptr, ART2_OUTFUNC))) {
  1143.             TOPO_MSG_OUT_FUNC (unit_ptr);
  1144.          } /*if*/
  1145.  
  1146.          unit_ptr->lln = ART2_INP_LAY;
  1147.          **topo_ptr = unit_ptr;
  1148.          unit_ptr->flags |= UFLAG_REFRESH;
  1149.          (*topo_ptr)++;
  1150.       } /*if*/
  1151.  
  1152.    } /*FOR_ALL_UNITS*/
  1153.  
  1154.    return (ret_code);
  1155.  
  1156. } /* kra2_get_InpUnits () */
  1157. /*___________________________________________________________________________*/
  1158.  
  1159.  
  1160.  
  1161. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  1162. static krui_err  kra2_get_WUnits (TopoPtrArray *topo_ptr, int *no_of_w_units)
  1163. {
  1164.    register struct Unit   *unit_ptr;
  1165.    register struct Unit   *unit_ptr2;
  1166.    register struct Link   *link_ptr;
  1167.    register struct Link   *link_ptr2;
  1168.  
  1169.    bool                   has_link_to_inp    = FALSE;
  1170.    bool                   has_outgoing_links = FALSE;
  1171.  
  1172.    krui_err               ret_code = KRERR_NO_ERROR;
  1173.  
  1174.  
  1175.    /* look for w units */
  1176.  
  1177.    FOR_ALL_UNITS (unit_ptr) {
  1178.  
  1179.       if (unit_ptr->lln == 0) {
  1180.  
  1181.          /* check if unit has direct inputs and link to inp unit */
  1182.  
  1183.          if (UNIT_HAS_SITES (unit_ptr)) {
  1184.             TOPO_MSG_UNEXPECTED_SITES (unit_ptr);
  1185.          } else {
  1186.  
  1187.             has_link_to_inp = FALSE;
  1188.             has_outgoing_links = FALSE;
  1189.  
  1190.             FOR_ALL_LINKS (unit_ptr, link_ptr) {
  1191.                if (link_ptr->to->lln == ART2_INP_LAY) {
  1192.                   has_link_to_inp = TRUE;
  1193.                   break;
  1194.                } /*if*/
  1195.             } /*FOR_ALL_UNITS*/
  1196.  
  1197.             /* check if unit_ptr->  has outgoing links */
  1198.  
  1199.             FOR_ALL_UNITS (unit_ptr2) {
  1200.                if (UNIT_HAS_SITES (unit_ptr2)) {
  1201.                   TOPO_MSG_UNEXPECTED_SITES (unit_ptr2);
  1202.                } else {
  1203.                   FOR_ALL_LINKS (unit_ptr2, link_ptr2) {
  1204.                      if (link_ptr2->to == unit_ptr) {
  1205.                         has_outgoing_links = TRUE;
  1206.                         break;
  1207.                      } /*if*/
  1208.                   } /*FOR_ALL_LINKS*/
  1209.                } /*if*/
  1210.  
  1211.                if (has_outgoing_links) {
  1212.                   break;
  1213.                } /*if*/
  1214.             } /*FOR_ALL_UNITS*/
  1215.  
  1216.             /* if unit has link to input unit and has outgoing links it
  1217.                is a w unit
  1218.             */
  1219.             if (has_link_to_inp && has_outgoing_links) {
  1220.  
  1221.                if (!(CHECK_ACT_FUNC (unit_ptr, ART2_ACTF_W))) {
  1222.                   TOPO_MSG_ACT_FUNC (unit_ptr);
  1223.                } /*if*/
  1224.  
  1225.                if (!(CHECK_OUT_FUNC (unit_ptr, ART2_OUTFUNC))) {
  1226.                   TOPO_MSG_OUT_FUNC (unit_ptr);
  1227.                } /*if*/
  1228.  
  1229.                if (! (UNIT_REFRESHED (unit_ptr))) {
  1230.                   unit_ptr->lln = ART2_W_LAY;
  1231.                   (*no_of_w_units)++;
  1232.                   **topo_ptr = unit_ptr;
  1233.                   unit_ptr->flags |= UFLAG_REFRESH;
  1234.                   (*topo_ptr)++;
  1235.                } /*if*/
  1236.  
  1237.             }  /*if*/
  1238.  
  1239.          } /*if*/
  1240.  
  1241.       } /*if*/
  1242.  
  1243.    } /*FOR_ALL_UNITS*/
  1244.  
  1245.    return (ret_code);
  1246.  
  1247. } /* kra2_get_WUnits () */
  1248. /*___________________________________________________________________________*/
  1249.  
  1250.  
  1251.  
  1252. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  1253. static krui_err kra2_get_XUnits (TopoPtrArray *topo_ptr, int *no_of_x_units)
  1254. {
  1255.    krui_err               ret_code   = KRERR_NO_ERROR;
  1256.  
  1257.    register struct Unit   *unit_ptr;
  1258.    register struct Link   *link_ptr;
  1259.  
  1260.    bool                   has_link_to_w;
  1261.  
  1262.    FOR_ALL_UNITS (unit_ptr) {
  1263.  
  1264.      if (UNIT_HAS_SITES (unit_ptr)) {
  1265.         TOPO_MSG_UNEXPECTED_SITES (unit_ptr);
  1266.      } else {
  1267.  
  1268.         has_link_to_w = FALSE;
  1269.  
  1270.         FOR_ALL_LINKS (unit_ptr, link_ptr) {
  1271.            if (link_ptr->to->lln == ART2_W_LAY) {
  1272.               has_link_to_w = TRUE;
  1273.               break;
  1274.            } /*if*/
  1275.         } /*FOR_ALL_LINKS*/
  1276.      } /*if*/
  1277.  
  1278.      if (has_link_to_w) {
  1279.  
  1280.         if (!(CHECK_ACT_FUNC (unit_ptr, ART2_ACTF_X))) {
  1281.            TOPO_MSG_ACT_FUNC (unit_ptr);
  1282.         } /*if*/
  1283.  
  1284.         if (! (UNIT_REFRESHED (unit_ptr))) {
  1285.            unit_ptr->lln = ART2_X_LAY;
  1286.            (*no_of_x_units)++;
  1287.            **topo_ptr = unit_ptr;
  1288.            unit_ptr->flags |= UFLAG_REFRESH;
  1289.            (*topo_ptr)++;
  1290.         } /*if*/
  1291.  
  1292.      } /*if*/
  1293.  
  1294.    } /*FOR_ALL_UNITS*/
  1295.  
  1296.    return (ret_code);
  1297.  
  1298. } /* kra2_get_XUnits () */
  1299. /*___________________________________________________________________________*/
  1300.  
  1301.  
  1302.  
  1303. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  1304. static krui_err kra2_get_UUnits (TopoPtrArray *topo_ptr, int *no_of_u_units)
  1305. {
  1306.    register struct Unit    *unit_ptr1;
  1307.    register struct Unit    *unit_ptr2 = NULL;
  1308.    register struct Link    *link_ptr;
  1309.  
  1310.    bool                    is_u_unit;
  1311.  
  1312.    krui_err                ret_code   = KRERR_NO_ERROR;
  1313.  
  1314.    FOR_ALL_UNITS (unit_ptr1) {
  1315.  
  1316.       if (unit_ptr1->lln == ART2_W_LAY) {
  1317.  
  1318.          is_u_unit = FALSE;
  1319.  
  1320.          FOR_ALL_LINKS (unit_ptr1, link_ptr) {
  1321.  
  1322.             unit_ptr2=link_ptr->to;
  1323.             if (unit_ptr2->lln != ART2_INP_LAY) {
  1324.                is_u_unit = TRUE;
  1325.                break;
  1326.             } /*if*/
  1327.  
  1328.          } /*FOR_ALL_LINKS*/
  1329.  
  1330.  
  1331.          if (is_u_unit) {
  1332.  
  1333.             if (!(CHECK_ACT_FUNC (unit_ptr2, ART2_ACTF_U))) {
  1334.                TOPO_MSG_ACT_FUNC (unit_ptr2);
  1335.             } /*if*/
  1336.  
  1337.             if (!(CHECK_OUT_FUNC (unit_ptr2, ART2_OUTFUNC))) {
  1338.                TOPO_MSG_OUT_FUNC (unit_ptr2);
  1339.             } /*if*/
  1340.  
  1341.             if (! (UNIT_REFRESHED (unit_ptr2))) {
  1342.                unit_ptr2->lln = ART2_U_LAY;
  1343.                (*no_of_u_units)++;
  1344.                **topo_ptr = unit_ptr2;
  1345.                unit_ptr2->flags |= UFLAG_REFRESH;
  1346.                (*topo_ptr)++;
  1347.             } /*if*/
  1348.  
  1349.          }  /*if*/
  1350.  
  1351.       } /*if*/
  1352.  
  1353.    } /*FOR_ALL_UNITS*/
  1354.  
  1355.    return (ret_code);
  1356.  
  1357. } /* kra2_get_UUnits () */
  1358. /*___________________________________________________________________________*/
  1359.  
  1360.  
  1361.  
  1362. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  1363. static krui_err kra2_get_VUnits (TopoPtrArray *topo_ptr, int *no_of_v_units)
  1364. {
  1365.    register struct Unit  *unit_ptr;
  1366.    register struct Link  *link_ptr;
  1367.    bool                  has_link_to_x;
  1368.  
  1369.    krui_err               ret_code   = KRERR_NO_ERROR;
  1370.  
  1371.    FOR_ALL_UNITS (unit_ptr) {
  1372.  
  1373.       if (unit_ptr->lln == 0) {
  1374.  
  1375.          if (UNIT_HAS_SITES (unit_ptr)) {
  1376.             TOPO_MSG_UNEXPECTED_SITES (unit_ptr);
  1377.          } else {
  1378.             has_link_to_x = FALSE;
  1379.             FOR_ALL_LINKS (unit_ptr, link_ptr) {
  1380.                if (link_ptr->to->lln == ART2_X_LAY) {
  1381.                   has_link_to_x = TRUE;
  1382.                   break;
  1383.                } /*if*/
  1384.             } /*FOR_ALL_LINKS*/
  1385.          } /*if*/
  1386.  
  1387.          if (has_link_to_x) {
  1388.  
  1389.            if (!(CHECK_ACT_FUNC (unit_ptr, ART2_ACTF_V))) {
  1390.               TOPO_MSG_ACT_FUNC (unit_ptr);
  1391.            } /*if*/
  1392.  
  1393.            if (!(CHECK_OUT_FUNC (unit_ptr, ART2_OUTFUNC))) {
  1394.               TOPO_MSG_OUT_FUNC (unit_ptr);
  1395.            } /*if*/
  1396.  
  1397.            if (! (UNIT_REFRESHED (unit_ptr))) {
  1398.               unit_ptr->lln = ART2_V_LAY;
  1399.               (*no_of_v_units)++;
  1400.               **topo_ptr = unit_ptr;
  1401.               unit_ptr->flags |= UFLAG_REFRESH;
  1402.               (*topo_ptr)++;
  1403.            } /*if*/
  1404.  
  1405.          } /*if*/
  1406.  
  1407.       } /*if*/
  1408.  
  1409.    } /*FOR_ALL_UNITS*/
  1410.  
  1411.    return (ret_code);
  1412.  
  1413. } /* kra2_get_VUnits () */
  1414. /*___________________________________________________________________________*/
  1415.  
  1416.  
  1417.  
  1418. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  1419. static krui_err kra2_get_PUnits (TopoPtrArray *topo_ptr, int *no_of_p_units)
  1420. {
  1421.    register struct Unit   *unit_ptr;
  1422.    register struct Link   *link_ptr;
  1423.  
  1424.    bool                   is_p_unit;
  1425.  
  1426.    krui_err               ret_code   = KRERR_NO_ERROR;
  1427.  
  1428.    FOR_ALL_UNITS (unit_ptr) {
  1429.  
  1430.       if (unit_ptr->lln == 0) {
  1431.  
  1432.          if (UNIT_HAS_SITES (unit_ptr)) {
  1433.             TOPO_MSG_UNEXPECTED_SITES (unit_ptr);
  1434.          } else {
  1435.  
  1436.             is_p_unit = FALSE;
  1437.  
  1438.             FOR_ALL_LINKS (unit_ptr, link_ptr) {
  1439.  
  1440.                if ((unit_ptr->lln != ART2_W_LAY) &&
  1441.                    (link_ptr->to->lln == ART2_U_LAY)
  1442.                   )
  1443.                {
  1444.                   is_p_unit = TRUE;
  1445.                   break;
  1446.                } /*if*/
  1447.  
  1448.             } /*FOR_ALL_UNITS*/
  1449.  
  1450.             if (is_p_unit) {
  1451.  
  1452.                if (!(CHECK_ACT_FUNC (unit_ptr, ART2_ACTF_P))) {
  1453.                   TOPO_MSG_ACT_FUNC (unit_ptr);
  1454.                } /*if*/
  1455.  
  1456.                if (!(CHECK_OUT_FUNC (unit_ptr, ART2_OUTFUNC))) {
  1457.                   TOPO_MSG_OUT_FUNC (unit_ptr);
  1458.                } /*if*/
  1459.  
  1460.                if (! (UNIT_REFRESHED (unit_ptr))) {
  1461.                   unit_ptr->lln = ART2_P_LAY;
  1462.                   (*no_of_p_units)++;
  1463.                   **topo_ptr = unit_ptr;
  1464.                   unit_ptr->flags |= UFLAG_REFRESH;
  1465.                   (*topo_ptr)++;
  1466.                } /*if*/
  1467.  
  1468.             } /*if*/
  1469.  
  1470.          } /*if*/
  1471.  
  1472.       } /*if*/
  1473.  
  1474.    } /*FOR_ALL_UNITS*/
  1475.  
  1476.    return (ret_code);
  1477.  
  1478. } /* kra2_get_PUnits () */
  1479. /*___________________________________________________________________________*/
  1480.  
  1481.  
  1482.  
  1483. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  1484. static krui_err  kra2_get_QUnits (TopoPtrArray *topo_ptr, int *no_of_q_units)
  1485. {
  1486.    register struct Unit   *unit_ptr;
  1487.    register struct Link   *link_ptr;
  1488.  
  1489.    bool                   has_link_to_p;
  1490.    bool                   has_link_to_other;
  1491.  
  1492.    krui_err               ret_code   = KRERR_NO_ERROR;
  1493.  
  1494.    FOR_ALL_UNITS (unit_ptr) {
  1495.  
  1496.       if (unit_ptr->lln == 0) {
  1497.  
  1498.          if (UNIT_HAS_SITES (unit_ptr)) {
  1499.             TOPO_MSG_UNEXPECTED_SITES (unit_ptr);
  1500.          } else {
  1501.  
  1502.             has_link_to_p     = FALSE;
  1503.             has_link_to_other = FALSE;
  1504.  
  1505.             FOR_ALL_LINKS (unit_ptr, link_ptr) {
  1506.  
  1507.                switch (link_ptr->to->lln) {
  1508.                case ART2_P_LAY:
  1509.                   has_link_to_p = TRUE;
  1510.                   break;
  1511.                default:
  1512.                   has_link_to_other = TRUE;
  1513.                   break;
  1514.                } /*switch*/
  1515.  
  1516.             } /*FOR_ALL_LINKS*/
  1517.  
  1518.             if ((has_link_to_p) && (! has_link_to_other)) {
  1519.  
  1520.                if (!(CHECK_ACT_FUNC (unit_ptr, ART2_ACTF_Q))) {
  1521.                   TOPO_MSG_ACT_FUNC (unit_ptr);
  1522.                } /*if*/
  1523.  
  1524.                if (! (UNIT_REFRESHED (unit_ptr))) {
  1525.                   unit_ptr->lln = ART2_Q_LAY;
  1526.                   (*no_of_q_units)++;
  1527.                   **topo_ptr = unit_ptr;
  1528.                   unit_ptr->flags |= UFLAG_REFRESH;
  1529.                   (*topo_ptr)++;
  1530.                } /*if*/
  1531.  
  1532.             } /*if*/
  1533.  
  1534.          } /*if*/
  1535.  
  1536.       } /*if*/
  1537.  
  1538.    } /*FOR_ALL_UNITS*/
  1539.  
  1540.    return (ret_code);
  1541.  
  1542. } /* kra2_get_QUnits () */
  1543. /*___________________________________________________________________________*/
  1544.  
  1545.  
  1546.  
  1547. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  1548. static krui_err kra2_get_RUnits (TopoPtrArray *topo_ptr, int *no_of_r_units)
  1549. {
  1550.    register struct Unit   *unit_ptr;
  1551.    register struct Link   *link_ptr;
  1552.  
  1553.    bool                   has_link_to_p;
  1554.    bool                   has_link_to_inp;
  1555.  
  1556.    krui_err               ret_code   = KRERR_NO_ERROR;
  1557.  
  1558.    FOR_ALL_UNITS (unit_ptr) {
  1559.  
  1560.       if (unit_ptr->lln == 0) {
  1561.  
  1562.          if (UNIT_HAS_SITES (unit_ptr)) {
  1563.             TOPO_MSG_UNEXPECTED_SITES (unit_ptr);
  1564.          } else {
  1565.  
  1566.             has_link_to_inp = FALSE;
  1567.             has_link_to_p   = FALSE;
  1568.  
  1569.             FOR_ALL_LINKS (unit_ptr, link_ptr) {
  1570.  
  1571.                switch (link_ptr->to->lln) {
  1572.                case ART2_INP_LAY:
  1573.                   has_link_to_inp = TRUE;
  1574.                   break;
  1575.                case ART2_P_LAY:
  1576.                   has_link_to_p = TRUE;
  1577.                   break;
  1578.                } /*switch*/
  1579.  
  1580.             } /*FOR_ALL_LINKS*/
  1581.  
  1582.             if (has_link_to_inp && has_link_to_p) {
  1583.  
  1584.                if (!(CHECK_ACT_FUNC (unit_ptr, ART2_ACTF_R))) {
  1585.                   TOPO_MSG_ACT_FUNC (unit_ptr);
  1586.                } /*if*/
  1587.  
  1588.                if (!(CHECK_OUT_FUNC (unit_ptr, ART2_OUTFUNC))) {
  1589.                   TOPO_MSG_OUT_FUNC (unit_ptr);
  1590.                } /*if*/
  1591.  
  1592.                if (! (UNIT_REFRESHED (unit_ptr))) {
  1593.                   unit_ptr->lln = ART2_R_LAY;
  1594.                   (*no_of_r_units)++;
  1595.                   **topo_ptr = unit_ptr;
  1596.                   unit_ptr->flags |= UFLAG_REFRESH;
  1597.                   (*topo_ptr)++;
  1598.                } /*if*/
  1599.  
  1600.             } /*if*/
  1601.  
  1602.          } /*if*/
  1603.  
  1604.       } /*if*/
  1605.  
  1606.    } /*FOR_ALL_UNITS*/
  1607.  
  1608.    return (ret_code);
  1609.  
  1610. } /* kra2_get_RUnits () */
  1611. /*___________________________________________________________________________*/
  1612.  
  1613.  
  1614.  
  1615. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  1616. static krui_err kra2_get_RecUnits (TopoPtrArray *topo_ptr)
  1617. {
  1618.    register struct Unit  *unit_ptr;
  1619.  
  1620.    krui_err               ret_code   = KRERR_NO_ERROR;
  1621.  
  1622.    FOR_ALL_UNITS (unit_ptr) {
  1623.  
  1624.       if ((unit_ptr->lln == 0) && (IS_SPECIAL_UNIT (unit_ptr))) {
  1625.  
  1626.          if (!(CHECK_ACT_FUNC (unit_ptr, ART2_ACTF_REC))) {
  1627.             TOPO_MSG_ACT_FUNC (unit_ptr);
  1628.          } /*if*/
  1629.  
  1630.          if (!(CHECK_OUT_FUNC (unit_ptr, ART2_OUTFUNC))) {
  1631.             TOPO_MSG_OUT_FUNC (unit_ptr);
  1632.          } /*if*/
  1633.  
  1634.          if (! (UNIT_REFRESHED (unit_ptr))) {
  1635.             unit_ptr->lln = ART2_REC_LAY;
  1636.             **topo_ptr = unit_ptr;
  1637.             unit_ptr->flags |= UFLAG_REFRESH;
  1638.             (*topo_ptr)++;
  1639.          } /*if*/
  1640.  
  1641.       } /*if*/
  1642.  
  1643.    } /*FOR_ALL_UNITS*/
  1644.  
  1645.    return (ret_code);
  1646.  
  1647. } /* kra2_get_RecUnits () */
  1648. /*___________________________________________________________________________*/
  1649.  
  1650.  
  1651.  
  1652. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  1653. static krui_err kra2_get_RstUnits (TopoPtrArray *topo_ptr, int *no_of_rst_units)
  1654. {
  1655.    register struct Unit   *unit_ptr;
  1656.  
  1657.    krui_err               ret_code   = KRERR_NO_ERROR;
  1658.  
  1659.    FOR_ALL_UNITS (unit_ptr) {
  1660.  
  1661.       if (unit_ptr->lln == 0)  {
  1662.  
  1663.          if (!(CHECK_ACT_FUNC (unit_ptr, ART2_ACTF_RST))) {
  1664.             TOPO_MSG_ACT_FUNC (unit_ptr);
  1665.          } /*if*/
  1666.  
  1667.          if (!(CHECK_OUT_FUNC (unit_ptr, ART2_OUTFUNC))) {
  1668.             TOPO_MSG_OUT_FUNC (unit_ptr);
  1669.          } /*if*/
  1670.  
  1671.          if (! (UNIT_REFRESHED (unit_ptr))) {
  1672.             unit_ptr->lln = ART2_RST_LAY;
  1673.             (*no_of_rst_units)++;
  1674.             **topo_ptr = unit_ptr;
  1675.             unit_ptr->flags |= UFLAG_REFRESH;
  1676.             (*topo_ptr)++;
  1677.          } /*if*/
  1678.  
  1679.       } /*if*/
  1680.  
  1681.    } /*FOR_ALL_UNITS*/
  1682.  
  1683.    return (ret_code);
  1684.  
  1685. } /* kra2_get_RstUnits () */
  1686. /*___________________________________________________________________________*/
  1687.  
  1688.  
  1689.  
  1690. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  1691. static krui_err  kra2_TopoPtrArray (void)
  1692. {
  1693.    TopoPtrArray    topo_inp_w_sep,
  1694.                    topo_w_x_sep,
  1695.                    topo_x_u_sep,
  1696.                    topo_u_v_sep,
  1697.                    topo_v_p_sep,
  1698.                    topo_p_q_sep,
  1699.                    topo_q_r_sep,
  1700.                    topo_r_rec_sep,
  1701.                    topo_rec_rst_sep,
  1702.                    topo_ptr_array_end;
  1703.  
  1704.    krui_err        ret_code = KRERR_NO_ERROR;
  1705.  
  1706.    topo_inp_w_sep   = topo_ptr_array + NoOfInputUnits + 1;
  1707.    topo_w_x_sep     = topo_inp_w_sep + NoOfInputUnits + 1;
  1708.    topo_x_u_sep     = topo_w_x_sep   + NoOfInputUnits + 1;
  1709.    topo_u_v_sep     = topo_x_u_sep   + NoOfInputUnits + 1;
  1710.    topo_v_p_sep     = topo_u_v_sep   + NoOfInputUnits + 1;
  1711.    topo_p_q_sep     = topo_v_p_sep   + NoOfInputUnits + 1;
  1712.    topo_q_r_sep     = topo_p_q_sep   + NoOfInputUnits + 1;
  1713.    topo_r_rec_sep   = topo_q_r_sep   + NoOfInputUnits + 1;
  1714.    topo_rec_rst_sep = topo_r_rec_sep + Art2_NoOfRecUnits + 1;
  1715.    topo_ptr_array_end = topo_rec_rst_sep + Art2_NoOfRecUnits + 1;
  1716.  
  1717.    if ((*topo_inp_w_sep   != NULL) ||
  1718.        (*topo_w_x_sep     != NULL) ||
  1719.        (*topo_x_u_sep     != NULL) ||
  1720.        (*topo_u_v_sep     != NULL) ||
  1721.        (*topo_v_p_sep     != NULL) ||
  1722.        (*topo_p_q_sep     != NULL) ||
  1723.        (*topo_q_r_sep     != NULL) ||
  1724.        (*topo_r_rec_sep   != NULL) ||
  1725.        (*topo_rec_rst_sep != NULL) ||
  1726.        (*topo_ptr_array_end  != NULL)
  1727.       )
  1728.    {
  1729.       ART2_RETURN_NET_ERROR (ret_code);
  1730.    } /*if*/
  1731.  
  1732.    return (ret_code);
  1733.  
  1734. } /* kra2_TopoPtrArray () */
  1735. /*___________________________________________________________________________*/
  1736.  
  1737.  
  1738.  
  1739. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  1740. static krui_err   kra2_LinksToInpUnits (TopoPtrArray *topo_ptr)
  1741. {
  1742.    register struct Unit   *unit_ptr;
  1743.  
  1744.    krui_err               ret_code = KRERR_NO_ERROR;
  1745.  
  1746.    while ((unit_ptr = *(*topo_ptr)++) != NULL) {
  1747.  
  1748.       if (UNIT_HAS_INPUTS (unit_ptr)) {
  1749.          topo_msg.error_code = KRERR_I_UNITS_CONNECT;
  1750.          topo_msg.dest_error_unit = unit_ptr-unit_array;
  1751.          topo_msg.src_error_unit = 0;
  1752.          ret_code = topo_msg.error_code;
  1753.       } /*if*/
  1754.  
  1755.    } /*while*/
  1756.  
  1757.    return (ret_code);
  1758.  
  1759. } /* kra2_LinksToInpUnits () */
  1760. /*___________________________________________________________________________*/
  1761.  
  1762.  
  1763.  
  1764. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  1765. static krui_err kra2_LinksToWUnits (TopoPtrArray *topo_ptr)
  1766. {
  1767.    register struct Unit   *unit_ptr;
  1768.    register struct Link   *link_ptr;
  1769.    int                    count_inp, count_u;
  1770.    krui_err               ret_code = KRERR_NO_ERROR;
  1771.  
  1772.    krart_deleteTouchFlags();
  1773.  
  1774.    while ((unit_ptr = *(*topo_ptr)++) != NULL) {
  1775.  
  1776.       count_inp = 0;
  1777.       count_u   = 0;
  1778.  
  1779.       FOR_ALL_LINKS (unit_ptr, link_ptr) {
  1780.          switch (link_ptr->to->lln) {
  1781.          case ART2_INP_LAY:
  1782.             if ((UNIT_REFRESHED (link_ptr->to)) || (count_inp > 0)) {
  1783.                TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
  1784.             } /*if*/
  1785.             link_ptr->to->flags |= UFLAG_REFRESH;
  1786.             count_inp++;
  1787.             break;
  1788.          case ART2_U_LAY:
  1789.             if ((UNIT_REFRESHED (link_ptr->to)) || (count_u > 0)) {
  1790.                TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
  1791.             } /*if*/
  1792.             link_ptr->to->flags |= UFLAG_REFRESH;
  1793.             count_u++;
  1794.             break;
  1795.          default:
  1796.             TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
  1797.          } /*switch*/
  1798.       } /*FOR_ALL_LINKS*/
  1799.  
  1800.       if ((count_inp != 1) || (count_u != 1)) {
  1801.          TOPO_MSG_LINK_MISSING (unit_ptr);
  1802.       } /*if*/
  1803.  
  1804.    } /*while*/
  1805.  
  1806.    return (ret_code);
  1807.  
  1808. } /* kra2_LinksToWUnits () */
  1809. /*___________________________________________________________________________*/
  1810.  
  1811.  
  1812.  
  1813. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  1814. static krui_err kra2_LinksToXUnits (TopoPtrArray *topo_ptr)
  1815. {
  1816.    register struct Unit   *unit_ptr;
  1817.    register struct Link   *link_ptr;
  1818.    int                    count_w;
  1819.    krui_err               ret_code = KRERR_NO_ERROR;
  1820.  
  1821.    krart_deleteTouchFlags();
  1822.  
  1823.    while ((unit_ptr = *(*topo_ptr)++) != NULL) {
  1824.  
  1825.       count_w   = 0;
  1826.  
  1827.       FOR_ALL_LINKS (unit_ptr, link_ptr) {
  1828.          switch (link_ptr->to->lln) {
  1829.          case ART2_W_LAY:
  1830.             if ((UNIT_REFRESHED (link_ptr->to)) || (count_w > 0)) {
  1831.                TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
  1832.             } /*if*/
  1833.             link_ptr->to->flags |= UFLAG_REFRESH;
  1834.             count_w++;
  1835.             break;
  1836.          default:
  1837.             TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
  1838.             break;
  1839.          } /*switch*/
  1840.       } /*FOR_ALL_LINKS*/
  1841.  
  1842.       if (count_w != 1) {
  1843.          TOPO_MSG_LINK_MISSING (unit_ptr);
  1844.       } /*if*/
  1845.  
  1846.    } /*while*/
  1847.  
  1848.    return (ret_code);
  1849.  
  1850. } /* kra2_LinksToXUnits () */
  1851. /*___________________________________________________________________________*/
  1852.  
  1853.  
  1854.  
  1855. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  1856. static krui_err kra2_LinksToUUnits (TopoPtrArray *topo_ptr)
  1857. {
  1858.    register struct Unit   *unit_ptr;
  1859.    register struct Link   *link_ptr;
  1860.    int                    count_v;
  1861.    krui_err               ret_code = KRERR_NO_ERROR;
  1862.  
  1863.    krart_deleteTouchFlags();
  1864.  
  1865.    while ((unit_ptr = *(*topo_ptr)++) != NULL) {
  1866.  
  1867.       count_v   = 0;
  1868.  
  1869.       FOR_ALL_LINKS (unit_ptr, link_ptr) {
  1870.          switch (link_ptr->to->lln) {
  1871.          case ART2_V_LAY:
  1872.             if ((UNIT_REFRESHED (link_ptr->to)) || (count_v > 0)) {
  1873.                TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
  1874.             } /*if*/
  1875.             link_ptr->to->flags |= UFLAG_REFRESH;
  1876.             count_v++;
  1877.             break;
  1878.          default:
  1879.             TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
  1880.             break;
  1881.          } /*switch*/
  1882.       } /*FOR_ALL_LINKS*/
  1883.  
  1884.       if (count_v != 1) {
  1885.          TOPO_MSG_LINK_MISSING (unit_ptr);
  1886.       } /*if*/
  1887.  
  1888.    } /*while*/
  1889.  
  1890.    return (ret_code);
  1891.  
  1892. } /* kra2_LinksToUUnits () */
  1893. /*___________________________________________________________________________*/
  1894.  
  1895.  
  1896.  
  1897. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  1898. static krui_err kra2_LinksToVUnits (TopoPtrArray *topo_ptr)
  1899. {
  1900.    register struct Unit   *unit_ptr;
  1901.    register struct Link   *link_ptr;
  1902.    int                    count_x, count_q;
  1903.    krui_err               ret_code = KRERR_NO_ERROR;
  1904.  
  1905.    krart_deleteTouchFlags();
  1906.  
  1907.    while ((unit_ptr = *(*topo_ptr)++) != NULL) {
  1908.  
  1909.       count_x   = 0;
  1910.       count_q   = 0;
  1911.  
  1912.       FOR_ALL_LINKS (unit_ptr, link_ptr) {
  1913.          switch (link_ptr->to->lln) {
  1914.          case ART2_X_LAY:
  1915.             if ((UNIT_REFRESHED (link_ptr->to)) || (count_x > 0)) {
  1916.                TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
  1917.             } /*if*/
  1918.             link_ptr->to->flags |= UFLAG_REFRESH;
  1919.             count_x++;
  1920.             break;
  1921.          case ART2_Q_LAY:
  1922.             if ((UNIT_REFRESHED (link_ptr->to)) || (count_q > 0)) {
  1923.                TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
  1924.             } /*if*/
  1925.             link_ptr->to->flags |= UFLAG_REFRESH;
  1926.             count_q++;
  1927.             break;
  1928.          default:
  1929.             TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
  1930.             break;
  1931.          } /*switch*/
  1932.       } /*FOR_ALL_LINKS*/
  1933.  
  1934.       if ((count_x != 1) || (count_q != 1)) {
  1935.          TOPO_MSG_LINK_MISSING (unit_ptr);
  1936.       } /*if*/
  1937.  
  1938.    } /*while*/
  1939.  
  1940.    return (ret_code);
  1941.  
  1942. } /* kra2_LinksToVUnits () */
  1943. /*___________________________________________________________________________*/
  1944.  
  1945.  
  1946.  
  1947. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  1948. static krui_err kra2_LinksToPUnits (TopoPtrArray *topo_ptr)
  1949. {
  1950.    register struct Unit   *unit_ptr;
  1951.    register struct Link   *link_ptr;
  1952.    int                    count_u, count_rec;
  1953.    krui_err               ret_code = KRERR_NO_ERROR;
  1954.  
  1955.    krart_deleteTouchFlags();
  1956.  
  1957.    while ((unit_ptr = *(*topo_ptr)++) != NULL) {
  1958.  
  1959.       count_u   = 0;
  1960.       count_rec = 0;
  1961.  
  1962.       FOR_ALL_LINKS (unit_ptr, link_ptr) {
  1963.          switch (link_ptr->to->lln) {
  1964.          case ART2_U_LAY:
  1965.             if ((UNIT_REFRESHED (link_ptr->to)) || (count_u > 0)) {
  1966.                TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
  1967.             } /*if*/
  1968.             link_ptr->to->flags |= UFLAG_REFRESH;
  1969.             count_u++;
  1970.             break;
  1971.          case ART2_REC_LAY:
  1972.             count_rec++;
  1973.             break;
  1974.          default:
  1975.             TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
  1976.             break;
  1977.          } /*switch*/
  1978.       } /*FOR_ALL_LINKS*/
  1979.  
  1980.       if ((count_u != 1) || (count_rec != Art2_NoOfRecUnits)) {
  1981.          TOPO_MSG_LINK_MISSING (unit_ptr);
  1982.       } /*if*/
  1983.  
  1984.    } /*while*/
  1985.  
  1986.    return (ret_code);
  1987.  
  1988. } /* kra2_LinksToPUnits () */
  1989. /*___________________________________________________________________________*/
  1990.  
  1991.  
  1992.  
  1993. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  1994. static krui_err kra2_LinksToQUnits (TopoPtrArray *topo_ptr)
  1995. {
  1996.    register struct Unit   *unit_ptr;
  1997.    register struct Link   *link_ptr;
  1998.    int                    count_p;
  1999.    krui_err               ret_code = KRERR_NO_ERROR;
  2000.  
  2001.    krart_deleteTouchFlags();
  2002.  
  2003.    while ((unit_ptr = *(*topo_ptr)++) != NULL) {
  2004.  
  2005.       count_p   = 0;
  2006.  
  2007.       FOR_ALL_LINKS (unit_ptr, link_ptr) {
  2008.          switch (link_ptr->to->lln) {
  2009.          case ART2_P_LAY:
  2010.             if ((UNIT_REFRESHED (link_ptr->to)) || (count_p > 0)) {
  2011.                TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
  2012.             } /*if*/
  2013.             link_ptr->to->flags |= UFLAG_REFRESH;
  2014.             count_p++;
  2015.             break;
  2016.          default:
  2017.             TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
  2018.             break;
  2019.          } /*switch*/
  2020.       } /*FOR_ALL_LINKS*/
  2021.  
  2022.       if (count_p != 1) {
  2023.          TOPO_MSG_LINK_MISSING (unit_ptr);
  2024.       } /*if*/
  2025.  
  2026.    } /*while*/
  2027.  
  2028.    return (ret_code);
  2029.  
  2030. } /* kra2_LinksToQUnits () */
  2031. /*___________________________________________________________________________*/
  2032.  
  2033.  
  2034.  
  2035. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  2036. static krui_err kra2_LinksToRUnits (TopoPtrArray *topo_ptr)
  2037. {
  2038.    register struct Unit   *unit_ptr;
  2039.    register struct Link   *link_ptr;
  2040.    int                    count_inp, count_p;
  2041.    krui_err               ret_code = KRERR_NO_ERROR;
  2042.  
  2043.    krart_deleteTouchFlags();
  2044.  
  2045.    while ((unit_ptr = *(*topo_ptr)++) != NULL) {
  2046.  
  2047.       count_inp = 0;
  2048.       count_p   = 0;
  2049.  
  2050.       FOR_ALL_LINKS (unit_ptr, link_ptr) {
  2051.          switch (link_ptr->to->lln) {
  2052.          case ART2_INP_LAY:
  2053.             if ((UNIT_REFRESHED (link_ptr->to)) || (count_inp > 0)) {
  2054.                TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
  2055.             } /*if*/
  2056.             link_ptr->to->flags |= UFLAG_REFRESH;
  2057.             count_inp++;
  2058.             break;
  2059.          case ART2_P_LAY:
  2060.             if ((UNIT_REFRESHED (link_ptr->to)) || (count_p > 0)) {
  2061.                TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
  2062.             } /*if*/
  2063.             link_ptr->to->flags |= UFLAG_REFRESH;
  2064.             count_p++;
  2065.             break;
  2066.          default:
  2067.             TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
  2068.             break;
  2069.          } /*switch*/
  2070.       } /*FOR_ALL_LINKS*/
  2071.  
  2072.       if ((count_inp != 1) || (count_p != 1)) {
  2073.          TOPO_MSG_LINK_MISSING (unit_ptr);
  2074.       } /*if*/
  2075.  
  2076.    } /*while*/
  2077.  
  2078.    return (ret_code);
  2079.  
  2080. } /* kra2_LinksToRUnits () */
  2081. /*___________________________________________________________________________*/
  2082.  
  2083.  
  2084.  
  2085. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  2086. static krui_err kra2_LinksToRecUnits (TopoPtrArray *topo_ptr)
  2087. {
  2088.    register struct Unit   *unit_ptr;
  2089.    register struct Link   *link_ptr;
  2090.    int                    count_p, count_rst;
  2091.    krui_err               ret_code = KRERR_NO_ERROR;
  2092.  
  2093.    krart_deleteTouchFlags();
  2094.  
  2095.    while ((unit_ptr = *(*topo_ptr)++) != NULL) {
  2096.  
  2097.       count_p   = 0;
  2098.       count_rst = 0;
  2099.  
  2100.       FOR_ALL_LINKS (unit_ptr, link_ptr) {
  2101.          switch (link_ptr->to->lln) {
  2102.          case ART2_P_LAY:
  2103.             count_p++;
  2104.             break;
  2105.          case ART2_RST_LAY:
  2106.             if ((UNIT_REFRESHED (link_ptr->to)) || (count_rst > 0)) {
  2107.                TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
  2108.             } /*if*/
  2109.             link_ptr->to->flags |= UFLAG_REFRESH;
  2110.             count_rst++;
  2111.             break;
  2112.          default:
  2113.             TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
  2114.             break;
  2115.          } /*switch*/
  2116.       } /*FOR_ALL_LINKS*/
  2117.  
  2118.       if ((count_p != NoOfInputUnits) || (count_rst != 1)) {
  2119.          TOPO_MSG_LINK_MISSING (unit_ptr);
  2120.       } /*if*/
  2121.  
  2122.    } /*while*/
  2123.  
  2124.    return (ret_code);
  2125.  
  2126. } /* kra2_LinksToRecUnits () */
  2127. /*___________________________________________________________________________*/
  2128.  
  2129.  
  2130.  
  2131. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  2132. static krui_err kra2_LinksToRstUnits (TopoPtrArray *topo_ptr)
  2133. {
  2134.    register struct Unit   *unit_ptr;
  2135.    register struct Link   *link_ptr;
  2136.    int                    count_rec;
  2137.    krui_err               ret_code = KRERR_NO_ERROR;
  2138.  
  2139.    krart_deleteTouchFlags();
  2140.  
  2141.    while ((unit_ptr = *(*topo_ptr)++) != NULL) {
  2142.  
  2143.       count_rec   = 0;
  2144.  
  2145.       FOR_ALL_LINKS (unit_ptr, link_ptr) {
  2146.          switch (link_ptr->to->lln) {
  2147.          case ART2_REC_LAY:
  2148.             if ((UNIT_REFRESHED (link_ptr->to)) || (count_rec > 0)) {
  2149.                TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
  2150.             } /*if*/
  2151.             link_ptr->to->flags |= UFLAG_REFRESH;
  2152.             count_rec++;
  2153.             break;
  2154.          default:
  2155.             TOPO_MSG_UNEXPECTED_LINK (link_ptr->to, unit_ptr);
  2156.             break;
  2157.          } /*switch*/
  2158.       } /*FOR_ALL_LINKS*/
  2159.  
  2160.       if (count_rec != 1) {
  2161.          TOPO_MSG_LINK_MISSING (unit_ptr);
  2162.       } /*if*/
  2163.  
  2164.    } /*while*/
  2165.  
  2166.    return (ret_code);
  2167.  
  2168. } /* kra2_LinksToRstUnits () */
  2169. /*___________________________________________________________________________*/
  2170.  
  2171.  
  2172.  
  2173. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  2174. static krui_err kra2_init_i_act (void)
  2175. {
  2176.    int                    ret_code = KRERR_NO_ERROR;
  2177.  
  2178.    register struct Unit   *unit_ptr;
  2179.  
  2180.  
  2181.    /* set initial activation values to 0.0 and
  2182.       copy actual activation values of input units into value_a field to
  2183.       remember it
  2184.    */
  2185.  
  2186.  
  2187.    FOR_ALL_UNITS (unit_ptr) {
  2188.  
  2189.          unit_ptr->i_act = 0.0;
  2190.  
  2191.    } /*FOR_ALL_UNITS*/
  2192.  
  2193.    return (ret_code);
  2194.  
  2195. } /* kra2_init_i_act () */
  2196. /*___________________________________________________________________________*/
  2197.  
  2198.  
  2199.  
  2200. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  2201. static krui_err kra2_init_fix_weights (void)
  2202. {
  2203.    int                    ret_code  = KRERR_NO_ERROR;
  2204.  
  2205.    register struct Unit   *unit_ptr;
  2206.    register struct Site   *site_ptr;
  2207.    register struct Link   *link_ptr;
  2208.  
  2209.  
  2210.  
  2211.  
  2212.    FOR_ALL_UNITS (unit_ptr) {
  2213.  
  2214.       if (UNIT_HAS_INPUTS (unit_ptr)) {
  2215.  
  2216.          if (UNIT_HAS_DIRECT_INPUTS (unit_ptr)) {
  2217.  
  2218.             FOR_ALL_LINKS (unit_ptr, link_ptr) {
  2219.  
  2220.                kra2_set_fix_weight (link_ptr->to, unit_ptr, &(link_ptr->weight));
  2221.  
  2222.             } /*FOR_ALL_LINKS*/
  2223.  
  2224.          } else {
  2225.  
  2226.             FOR_ALL_SITES_AND_LINKS (unit_ptr, site_ptr, link_ptr) {
  2227.  
  2228.                kra2_set_fix_weight (link_ptr->to, unit_ptr, &(link_ptr->weight));
  2229.  
  2230.             } /*FOR_ALL_SITES_AND_LINKS*/
  2231.  
  2232.          } /*if*/
  2233.  
  2234.       } /*if*/
  2235.  
  2236.    } /*FOR_ALL_UNITS*/
  2237.  
  2238.  
  2239.    return (ret_code);
  2240.  
  2241.  
  2242. } /* kra2_init_fix_weights () */
  2243. /*___________________________________________________________________________*/
  2244.  
  2245.  
  2246.